package com.supersoul.myself.util;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SmsUtil {

    /**
     * 发短信验证码
     * @param phone
     * @param code
     * @return Client
     * @throws Exception
     */
    public static void sendSms(String phone, String code) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId("LTAI5tJDEEVjvrChjKUcxgnT")
                // 您的AccessKey Secret
                .setAccessKeySecret("APm8xFucnaMvoqxfUzVM6s8gnWJpgI");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        Client client = new Client(config);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phone)
                .setSignName("supersoul")
                .setTemplateCode("SMS_218280501")
                .setTemplateParam("{\"code\":" + code + "}");
        // 复制代码运行请自行打印 API 的返回值
        client.sendSms(sendSmsRequest);
    }

}



